const redis = require("redis");
const client = redis.createClient();

client.on("error", function (error) {
  console.error(error);
});

module.exports = { 
  async get(key) {
    return new Promise((res,rej) => {
      client.get(key, function(err, reply) {
        if(err) rej(err)        
        res(reply)
      })
    })    
  },
  set(key, value, time) { 
    client.set(key, value);
    client.expire(key, time)
  },

  expire(key, time) {
    client.expire(key, time)
  },
  
  del(key) {
    client.del(key)
  }
}